import 'dart:async';

import 'package:iea/provider/base/base_resp.dart';

import 'package:iea/provider/resource/personalPage_api_provider.dart';

class UploadAvatarBloc {

// 初始化请求方法
final provider = PersonalPageApiProvider();

/*
   * 数据流取数据 3 部曲
   *
   */
// 声明数据流
StreamSubscription<BaseResp> _uploadSubcrition;
// 监听数据流
final StreamController<BaseResp> _uploadController = StreamController<BaseResp>.broadcast();
// 用流返回的数据
Stream<BaseResp> get upLoadImgStream => _uploadController.stream;



void upLoadAvatar (params) {
  // 数据异常 => cancel
  _uploadSubcrition?.cancel();

  _uploadSubcrition = provider.uploadImgUrl(params).asStream().listen((BaseResp data) {
    _uploadController.add(data);
  });
}
// CANCEL 销毁控制器
void dispose() {
  _uploadSubcrition?.cancel();
  _uploadController.close();
}
}
